package com.itelite.config;

import com.github.pagehelper.PageHelper;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Properties;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    //配置mybatis的分页插件pageHelper
        @Bean
        public PageHelper pageHelper(){
             PageHelper pageHelper = new PageHelper();
             Properties properties = new Properties();
             properties.setProperty("offsetAsPageNum","true");
             properties.setProperty("rowBoundsWithCount","true");
             properties.setProperty("reasonable","true");
             properties.setProperty("dialect","mysql");    //配置mysql数据库的方言
             pageHelper.setProperties(properties);
             return pageHelper;
        }
    @Bean
    public Producer captcha(){
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width","150");
        properties.setProperty("kaptcha.image.height","50");
        properties.setProperty("kaptcha.textproducer.char.string","0123456789");
        //字符长度
        properties.setProperty("kaptcha.textproducer.char.length","4");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
//    @Bean
//    public JavaMailSender getJavaMailSender() {
//        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
//        mailSender.setHost("smtp.qq.com");
//        mailSender.setPort(465);
//        mailSender.setUsername("sywxr_active@qq.com");
//        mailSender.setPassword("tgcpvailnjxljcaf");
//        Properties props = mailSender.getJavaMailProperties();
//        props.put("mail.transport.protocol", "smtp");
//        props.put("mail.smtp.auth", "true");
//        props.put("mail.smtp.starttls.enable", "true");
//        return mailSender;
//    }
}
